package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.AreaDO;
import com.smart.model.domain.CityDO;
import com.smart.model.domain.ProvinceDO;
import com.smart.model.domain.StreetDO;
import com.smart.model.request.StreetRequest;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface StreetMapper extends BaseMapper<StreetDO> {
    StreetDO selectDOByCode(String code);
    List<StreetDO> selectDOList(StreetDO street);
    int insertDO(StreetDO street);
    int batchInsertDO(List<StreetDO> streetDOList);
    int updateDO(StreetDO street);
    int deleteDOByCode(String code);
    int deleteDOByCodes(String[] codes);

    @Select({"<script>",
            "   select count(1) from street",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") StreetRequest param);
    @Select({"<script>",
            "   select * from street",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<StreetDO> pageQuery(@Param("param") StreetRequest param, @Param("limit") int limit, @Param("offset") long offset);

    List<Map<String, Object>> queryAllProvince();

    List<Map<String, Object>> queryCityByCode(@Param("code") String code);

    List<Map<String, Object>> queryAreaByCode(@Param("code")String code);

    List<ProvinceDO> queryAllProvinceList();

    List<CityDO> queryAllCityList();

    List<AreaDO> queryAllAreaList();

}
